// 采血登记
Ext.extend(CQCIS.module, {
    init: function() {
    	var listMeta = [{
			field: 'bloodId',
            desc: '采血序列号',
            width: 50
		}, {
		    field: 'bloodDonor',
            desc: '献血者姓名',
            width: 50
		}, {
            field: 'bloodNum',
            desc: '献血者身份证',
            width: 100
        }, {
            field: 'bloodType',
            desc: '献血者血型',
            renderer: function(value) {
                switch(value) {
                    case 'A':
                    return 'A型';
                    case 'B':
                    return 'B型';
                    case 'AB':
                    return 'AB型';
                    case 'O':
                    return 'O型';
                    case 'T':
                    return '稀有血型';
                }
                return value;
            },
            width: 40
        }, {
            field: 'bloodVolume',
            desc: '采血量（ML）',
            width: 60
        }, {
            field: 'takeType',
            desc: '采血类型',
            renderer: function(value) {
            	switch(value) {
            		case '1':
            		return '自愿献血';
            		case '2':
                    return '手术用血';
                    case '3':
                    return '有偿采血';
            	}
            	return value;
            },
            width: 50
        }, {
            field: 'workerId',
            desc: '采血者',
            renderer: function(value) {
            	workerDwr.getWorker(value, {
            		callback: function(worker) {
            			if (worker != null) {
            				value = worker.staffName;
            			}            			
            		},
            		async: false
            	});
            	
            	return value;
            },
            width: 80
        }, {
            field: 'takeTime',
            desc: '采血时间',
            type: 'date',
            width: 80
        }, {
            field: 'takeLocation',
            desc: '采血地点',
            renderer: function(value) {
            	takeLocationDwr.getTakeLocation(value, {
            		callback: function(local) {
            			if (local) {
            				value = local.locationName;
            			}
            		},
            		async: false
            	});
                                
                return value;
            },
            width: 100
        }];
        
        // 增加，修改页面列表
        var takeMeta = [{
            name: 'bloodId',
            fieldLabel: '采血序列号',
            xtype: 'hidden'
        }, {
            name: 'bloodDonor',
            fieldLabel: '献血者姓名',
            allowBlank: false,
            width: 100
        }, {
            name: 'bloodNum',
            fieldLabel: '献血者身份证',
            allowBlank: false,
            regex: /^[A-Za-z0-9](\d{15,15}|\d{18,18})$/,
            regexText: '身份证只能输入英文或数字,15或18位',
            width: 100
        }, {
           name: 'bloodType',
            fieldLabel: '献血者血型',            
            allowBlank: false,
            store: [['A', 'A型'], ['B', 'B型'], ['AB', 'AB型'], ['O', 'O型'], ['T', '稀有血型']],
            triggerAction: 'all',
            editable: false,
            xtype: 'combo',
            value: 'A'
        }, {
           name: 'bloodVolume',
            fieldLabel: '采血量（ML）',
            allowBlank: false,
            regex: /^[0-9]+$/,
            regexText: '采血量只能输入数字',
            width: 100,            
        }, {
           name: 'takeType',
            fieldLabel: '采血类型',
            store: [['1', '自愿献血'], ['2', '手术用血'], ['3', '有偿采血']],
            triggerAction: 'all',
            editable: false,
            xtype: 'combo',
            value: '1'            
        }, {
           name: 'workerId',
            fieldLabel: '采血者',
            allowBlank: false,
            fields: ['loginId', 'staffName'],
            valueField: 'loginId',
            displayField: 'staffName',
            ds: {
                call: workerDwr.getWorkers
            },
            xtype: 'rcombo'
        }, {
           name: 'takeTime',
            fieldLabel: '采血时间',
            type: 'date',
            xtype: 'datefield',
            width: 100
        }, {
           name: 'takeLocation',
            fieldLabel: '采血地点',
            allowBlank: false,
            fields: ['locationId', 'locationName'],
            valueField: 'locationId',
            displayField: 'locationName',
            ds: {
                call: takeLocationDwr.getTakeLocations
            },
            xtype: 'rcombo'
        }];
        
        var takeWin = new CQCIS.Window({
            id: 'sm_take_win',
            title: '采血登记信息',
            height: 300,
            width: 380,
            items: new CQCIS.form.DWRForm({
                dwr: {
                    save: takeDwr.take,
                    load: takeDwr.getTake,
                    update: takeDwr.updateTake
                },
                labelWidth: 100,
                items: takeMeta,
                afterSubmit: function() {
                    grid.refresh();
                }
            })
        });
        
        // 工具栏增加按钮
        var addBtn = new Ext.Toolbar.Button({
            text: '采血登记',
            iconCls: 'btn_insert',
            handler: function() {
                takeWin.show();
            }
        });
        
        // 工具栏修改按钮
        var editBtn = new Ext.Toolbar.Button({
            text: '修改记录',
            iconCls: 'btn_modify',
            handler: function() {
                var menu = grid.getSelectedRow();
                if (menu) {
                    takeWin.load(menu.bloodId);
                } else {
                    CQCIS.msg('请选择要修改的记录!');
                }
            }
        });
        
        // 员工信息grid
        var grid = new CQCIS.grid.PageGrid({
            id: 'sm_take_grid',
            firstColumn: 'radio',
            dwr: {
                call: takeDwr.pageTakes
            },
            metas: listMeta,
            tbar: [addBtn, ' - ', editBtn],
            initload: true,
            bbar: 'true'
        });
        
        // 定义关联销毁对象数组，避免内存泄漏
        this.main.associatedComp = [takeWin];
        // 定义页面主元素
        this.main.add(grid);
        // 布局更新
        this.main.doLayout();
    }
});